package HtServer.meeting;

import HtServer.RedisTools.RedisToos;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;

import java.util.Objects;

public class MeetingItem implements Comparable<MeetingItem> {

    @JSONField(name = "id")
    String id;
    @JSONField(name = "name")
    String name;

    @JSONField(name = "like")
    int like =0;
    @JSONField(name = "unlike")
    int unlike;
    @JSONField(name = "contents")
    String contents;

    @JSONField(name = "imagebase64")
    String image;

    @JSONField(name = "dept")
    String dept;


    @JSONField(name = "groupid")
    String groupid;

    @JSONField(name = "groupname")
    String groupname;

    @JSONField(name = "order")
    String order;

    //领域
    @JSONField(name = "lingyu")
    String lingyu;

    @JSONField(name = "randomnum")

    int randomnum;
    @JSONField(name = "color")
    String color = "";

    //抽签（1不会被抽中，2一定会被抽中，其他随机）
    //@See tools.Tools.Random
    @JSONField(name = "randomtype")
    int randomtype = 0;



    public void MeetingItem()
    {

    }
    public void addLike()
    {
        this.like++;
    }

    public void addUnLike()
    {
        this.unlike++;
    }


    public int getLike() {
        return like;
    }

    public void setLike(int like) {
        this.like = like;
    }

    public int getUnlike() {
        return unlike;
    }

    public void setUnlike(int unlike) {
        this.unlike = unlike;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getContents() {
        return contents;
    }

    public void setContents(String contents) {
        this.contents = contents;
    }

//    public byte[] getImage() {
//        return image;
//    }
//
//    public void setImage(byte[] image) {
//        this.image = image;
//    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getDept() {
        return dept;
    }

    public void setDept(String dept) {
        this.dept = dept;
    }

    public String getGroupid() {
        return groupid;
    }

    public void setGroupid(String groupid) {
        this.groupid = groupid;
    }

    public String getGroupname() {
        return groupname;
    }

    public void setGroupname(String groupname) {
        this.groupname = groupname;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public String getLingyu() {
        return lingyu;
    }

    public void setLingyu(String lingyu) {
        this.lingyu = lingyu;
    }

    public int getRandomnum() {
        return randomnum;
    }

    public void setRandomnum(int randomnum) {
        this.randomnum = randomnum;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public int getRandomtype() {
        return randomtype;
    }

    public void setRandomtype(int randomtype) {
        this.randomtype = randomtype;
    }

    @Override
    public String toString() {
        return "MeetingItem{" +
                "id='" + id + '\'' +
                "name='" + name + '\'' +
                ", like=" + like +
                ", unlike=" + unlike +
                ", dept='" + dept + '\'' +
//                ", groupid='" + groupid + '\'' +
//                ", groupname='" + groupname + '\'' +
                ", order='" + order + '\'' +

                ", contents='" + (contents!=null && contents.length()>10?contents.substring(0,10):contents) + '\'' +
                ", image='" + (image !=null && image.length()>10?"有图":"无图") + '\'' +
                ", lingyu='" + lingyu + '\'' +
                ", randomnum=" + randomnum +
                ", color='" + color + '\'' +
                ",randomtype="+randomtype+ '\'' +

                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof MeetingItem)) return false;
        MeetingItem that = (MeetingItem) o;
        if (name==null)
            return false;
        if(that.name==null)
            return false;
        return name.equals(that.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    public void saveMeetingItem2Redis()
    {
        RedisToos.getInstance().getJedis().set("meetingitem:"+this.getId(), JSON.toJSONString(this));
    }


    @Override
    public int compareTo(MeetingItem other) {

        if(this.order==null)
            return 1;
        if(other.order==null)
            return 0;
        try {
//            System.out.println("this.order:"+this.order);
//            System.out.println("other.order:"+other.order);
            double i = Double.parseDouble(this.order);
            double j = Double.parseDouble(other.order);

            return (int)(i-j);
        }catch (Exception e)
        {
            System.err.println("error in compare order");
            return 0;
        }

    }
}
